<?php

/**
 * This is the model class for table "lusi_classes".
 *
 * The followings are the available columns in table 'lusi_classes':
 * @property string $id
 * @property string $course_id
 * @property string $begin_date
 * @property string $end_date
 * @property string $class_time
 * @property integer $capacity
 * @property integer $total_members
 * @property integer $status
 *
 * The followings are the available model relations:
 * @property Courses $course
 * @property RegisterredCourses[] $registerredCourses
 */
class Classes extends CActiveRecord
{
	/**
	 * @var string
	 */
	public $id;

	/**
	 * @var string
	 */
	public $course_id;

	/**
	 * @var string
	 */
	public $begin_date;

	/**
	 * @var string
	 */
	public $end_date;

	/**
	 * @var string
	 */
	public $class_time;

	/**
	 * @var integer
	 */
	public $capacity;

	/**
	 * @var integer
	 */
	public $total_members;

	/**
	 * @var integer
	 */
	public $status;


 	/**
	 * @var Courses
	 */
	 public $Courses;

 	/**
	 * @var RegisterredCourses
	 */
	 public $RegisterredCourses;

	/**
	 * Returns the static model of the specified AR class.
	 * @return Classes the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'lusi_classes';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('course_id, begin_date, end_date, class_time, capacity', 'required'),
			array('capacity, total_members, status', 'numerical', 'integerOnly'=>true),
			array('course_id', 'length', 'max'=>11),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, course_id, begin_date, end_date, class_time, capacity, total_members, status', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'course' => array(self::BELONGS_TO, 'Courses', 'course_id'),
			'registerredCourses' => array(self::HAS_MANY, 'RegisterredCourses', 'class_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'course_id' => 'Course',
			'begin_date' => 'Begin Date',
			'end_date' => 'End Date',
			'class_time' => 'Class Time',
			'capacity' => 'Capacity',
			'total_members' => 'Total Members',
			'status' => 'Status',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id,true);
		$criteria->compare('course_id',$this->course_id,true);
		$criteria->compare('begin_date',$this->begin_date,true);
		$criteria->compare('end_date',$this->end_date,true);
		$criteria->compare('class_time',$this->class_time,true);
		$criteria->compare('capacity',$this->capacity);
		$criteria->compare('total_members',$this->total_members);
		$criteria->compare('status',$this->status);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}